package com.linwen.excise.leetcode;

import java.util.Arrays;

public class _724寻找数组的中心下标 {
    public static void main(String[] args) {
        int[] nums = new int[]{1, 7, 3, 6, 5, 6};
        System.out.println(pivotIndex(nums));

    }

    public static int pivotIndex(int[] nums) {
        if(nums.length==0){
            return 0;
        }
        int sum = Arrays.stream(nums).sum();
        int proSum = 0;
        for (int i = 0; i < nums.length; i++) {
            proSum += nums[i];
            if(proSum == sum){
                return i;
            }
            sum -= nums[i];
        }
        return -1;
    }
}
